package com.briup.serviceImp;

import com.briup.dao.CustomerMapper;
import com.briup.pojo.Customer;
import com.briup.service.CustomerService;
import com.briup.utils.ToolMan;
import org.apache.ibatis.session.SqlSession;

public class CustomerServiceImp implements CustomerService {


    @Override
    public void regist(Customer customer) {
        SqlSession sqlSession = ToolMan.getSqlSession();
        CustomerMapper mapper = sqlSession.getMapper(CustomerMapper.class);
        int insert = mapper.insert(customer);
        ToolMan.close(sqlSession);
    }

    @Override
    public Customer login(String username) {
        SqlSession sqlSession = ToolMan.getSqlSession();
        CustomerMapper mapper = sqlSession.getMapper(CustomerMapper.class);
        Customer customer = mapper.selectByUsername(username);
        ToolMan.close(sqlSession);
        return customer;
    }

    @Override
    public Boolean existName(String username) {
        SqlSession sqlSession = ToolMan.getSqlSession();
        CustomerMapper mapper = sqlSession.getMapper(CustomerMapper.class);
        String userName = mapper.selectByUserNmae(username);
        ToolMan.close(sqlSession);
        System.out.println(userName);
        if (userName == null) {
            return true;
        }
        return false;
    }

    @Override
    public int updateMsg(Customer customer) {
        SqlSession sqlSession = ToolMan.getSqlSession();
        CustomerMapper mapper = sqlSession.getMapper(CustomerMapper.class);
        int i = mapper.updateByUsername(customer);
        ToolMan.close(sqlSession);
        return i;
    }
}
